package edu.ilstu.mind.ise.ccp.impl.disruptor;

import com.lmax.disruptor.EventHandler;

import edu.ilstu.mind.ise.ccp.module.Module;

class ModuleEventHandler implements EventHandler<MessageEvent> {
	private final String name;
	private final Module module;
	
	public ModuleEventHandler(String name, Module module) {
		if(name == null) {
			throw new IllegalArgumentException("name cannot be null");
		}
		if(module == null) {
			throw new IllegalArgumentException("module cannot be null");
		}
		this.name = name;
		this.module = module;
	}

	@Override
	public void onEvent(MessageEvent event, long sequence, boolean endOfBatch) throws Exception {
		if(event.process && name.equals(event.message.getTo())) {
			module.processMessage(event.message);
		}
	}
}